

## 求序列极大值，极小值
a = [1,2,3,4,5,6,7,8,9,7,6,5,4,3,4,5,6,7,8,9,10,11,12,13,15,17,16,18,20,19,17,16,15,16,13,12]

scale = 0.4
max_v = a[0]
min_v = a[0]
is_up = a[1] > a[0]

for i in a:
    if is_up:
        if i > max_v:
            max_v = i
        elif i < max_v * (1 - scale):
            min_v = i
            is_up = False
    else:
        if i < min_v:
            min_v = i
        elif i > min_v * (1 + scale):
            max_v = i
            is_up = True
